
/*---
title: "Analysis for Table A5: The Dynamics of Electoral Manipulation and Institutional Trust in Democracies (POQ)"
author: "M. Higashijima, H. Kadoya, and Y. Yanai"
date: "2023-11-12"
---*/

/*If estout is not installed, run the following command
ssc install estout
*/


import delimited "data_reg_HKY_POQ_2023.csv", clear

destring *, replace ignore(NA)


**Table A5**
eststo clear

*model25: outcome = Trust in Government   Variance Components(country-level 0.082, year-level 0.059) N clusters 58
eststo: xtmixed gov i.early##c.dif_days10 fraud2 nelda17 nelda18 gdpgrowth_new ///
	gdppc_change margin_pty_lag v2x_polyarchy_excfraud age female unemployment urban ///
	|| cowcode: || year:, var mle

*model26: outcome = Trust in Parliament   Variance Components(country-level 0.072, year-level 0.040) N clusters 58
eststo: xtmixed pmt i.early##c.dif_days10 fraud2 nelda17 nelda18 gdpgrowth_new ///
	gdppc_change margin_pty_lag v2x_polyarchy_excfraud age female unemployment urban ///
	|| cowcode: || year:, var mle

*model27: outcome = Trust in EMB   Variance Components(country-level 0.000, year-level 0.062) N clusters 32 
eststo: xtmixed etn i.early##c.dif_days10 fraud2 nelda17 nelda18 gdpgrowth_new ///
	gdppc_change margin_pty_lag v2x_polyarchy_excfraud age female unemployment urban ///
	|| cowcode: || year:, var mle

 
	esttab * using "table_ind_reg_multi", /// 
		drop(_cons) order(1.early dif_days10 1.early#c.dif_days10 fraud2) ///
		coeflabels(1.early "Early election" dif_days10 "Days from last election" 1.early#c.dif_days10 "Early x Days" fraud2 "Electoral fraud" ///
		nelda17 "NELDA17" nelda18 "NELDA18" gdpgrowth_new "GDP growth" gdppc_change "Change in GDP per capita" margin_pty_lag "Electoral margin" /// 		
		v2x_polyarchy_excfraud "Polyarchy" age "Age" female "Gender (female)" unemployment "Unemployment" urban "Urban") /// 
		p(3) b(3) nostar varwidth(23) nogaps mtitles("(25)" "(26)" "(27)") nobaselevels nonote ///
		addnotes("Note: p-values calculated with standard errors in parentheses. p-values refer to two-tailed tests. All models are estimated with two-level (country and year) random intercept mixed-effects estimators.") replace tex 
		
	